package cn.liutao.dish.api;

import cn.hutool.core.util.StrUtil;
import cn.liutao.common.enums.CommonEnum;
import cn.liutao.common.exception.OrderException;
import cn.liutao.common.utils.ServletUtils;
import cn.liutao.dish.entity.po.Dish;
import cn.liutao.dish.entity.vo.DishVo;
import cn.liutao.dish.service.DishService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author liutao
 * @Description dishItem关联查询
 * @date 2023/11/1 10:41
 * @Version 1.0
 */
@WebServlet("/dishItem")
public class DishItemServlet extends HttpServlet {
    private DishService dishService;
    @Override
    public void init() throws ServletException {
        dishService = DishService.getInstance();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer id = Integer.valueOf(req.getParameter("id"));
        if (id==null){
            throw new OrderException("请选择菜品");
        }
        DishVo dishVo = dishService.selectById(id);
        if (StrUtil.isBlank(dishVo.getImg())) dishVo.setImg(CommonEnum.DEFAULT_DISH_IMAGE.getValue());
        ServletUtils.ok(resp,dishVo);
    }
}
